<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use App\Models\Article;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Parsedown;

class ArticleController extends Controller
{
    /**
     * 文章数据
     */
    public function index(Request $request)
    {
        $article=Article::with('cate:id,name,thumb')->find($request->articleId);

        //增加点击量
        $article->increment('view_times');

        return webJson($article);
    }

    /**
     * 所有文章,列表页使用
     */
    public function articleList()
    {
        $articles=Article::with(['cate:id,name'])
            ->select(['id','title','created_at','cate_id'])
            ->orderBy('updated_at','desc')
            ->get();

        return webJson($articles);
    }

    /**
     * 获取全部的文章数据
     */
    public function articles()
    {
        $articles=Article::with(['cate:id,name,thumb'])
            ->select(['id','title','description','content','thumb','content_file','created_at','cate_id'])
            ->get();

        return webJson($articles);
    }

}
